package com.xuecheng.media.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Author xiao
 * @Date 2024/12/10 14:21
 * @ClassName: SwaggerConfig
 * @Description: TODO
 */
@Configuration
public class SwaggerConfig {
    @Value("${knife4j.docket.groupName}")
    private String groupName;
    @Value("${knife4j.docket.title}")
    private String title;
    @Value("${knife4j.docket.version}")
    private String version;
    @Value("${knife4j.docket.description}")
    private String description;
    @Value("${knife4j.docket.base-package}")
    private String basePackage;

    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(groupName)
                .apiInfo( new ApiInfoBuilder()
                        .title(title)
                        .version(version)
                        .description(description)
                        .build()
                )
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 设置静态资源映射
     *
     * @param registry
     */
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }


}
